import { ref } from 'vue'
import { defineStore } from 'pinia'
import { getUserInfoService } from '@/api/user'


export const useUserStore = defineStore('user', () => {
  const user = ref({})
  const token = ref('')

  const getUser = async () => {
    const result = await getUserInfoService();
    console.log('用户信息：', result);
    user.value = result.data
  }

  const setToken = async (value) => {
    console.log('setToken:', value);
    token.value = value
  }

  const logout = () => {
    user.value = {}
    token.value = ''
  }

  return {
    user,
    getUser,
    token,
    setToken,
    logout,
  }
},
  {
    persist: true // 开启持久化
  })
